package demo2;

import java.util.LinkedList;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        ListNode node1 = new ListNode(12);
        ListNode node2 = new ListNode(13);
        ListNode node3 = new ListNode(12);
        ListNode node4 = new ListNode(12);
        ListNode node5 = new ListNode(12);
        node1.next = node2;
        node2.prev = node1;
        node2.next = node3;
        node3.prev = node2;
        node3.next = node4;
        node4.prev = node3;
        node4.next = node5;
        node5.prev = node4;
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.head = node1;
        myLinkedList.last = node5;
        myLinkedList.removeAllKey(12);
        myLinkedList.display();
        myLinkedList.clear();
        myLinkedList.display();
        LinkedList<Integer> linkedList = new LinkedList<>();
        linkedList.add(12);
        linkedList.add(13);
        linkedList.add(14);
        //利用迭代器正向打印
        ListIterator<Integer> it = linkedList.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
        //利用迭代器反向打印
        ListIterator<Integer> it2 = linkedList.listIterator(linkedList.size());
        while (it2.hasPrevious()) {
            System.out.print(it2.previous() + " ");
        }
    }
}
